package household.household.mvc;

import java.util.Date;
import java.util.List;

import household.household.model.SettleHousehold;
import household.household.service.SettleHouseholdService;
import household.util.FlexigridForm;
import household.util.IFlexigridJson;
import household.util.IModelAndView;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/settle")
public class SettleHouseholdController {
	
	@Autowired
	public SettleHouseholdService settleHouseholdService;
	
	@RequestMapping("/newview.htm")
	public IModelAndView newSettleHousehold(SettleHousehold settleHousehold){		
		int id = settleHouseholdService.save(settleHousehold);
		IModelAndView view = new IModelAndView("jsonView",id);
		System.out.println("id:"+id);
		return view;
	}
	
	@RequestMapping("/updateview.htm")
	public IModelAndView updateSettleHousehold(SettleHousehold settleHousehold){		
		boolean status = settleHouseholdService.update(settleHousehold);
		IModelAndView view = new IModelAndView("jsonView",status);
		System.out.println("status:"+status);
		return view;
	}
	
	@RequestMapping("/deleteview.htm")
	public IModelAndView deleteSettleHousehold(int id){		
		boolean status = settleHouseholdService.delete(id);
		IModelAndView view = new IModelAndView("jsonView",status);
		System.out.println("status:"+status);
		return view;
	}
	
	@RequestMapping("/getview.htm")
	public IModelAndView getSettleHousehold(int id){		
		SettleHousehold settleHousehold = settleHouseholdService.get(id);
		IModelAndView view = new IModelAndView("jsonView",settleHousehold);
		System.out.println("settleHousehold:"+settleHousehold);
		return view;
	}
	
	@RequestMapping("/getallview.htm")
	public IModelAndView getAllSettleHousehold(){		
		List<SettleHousehold> list = settleHouseholdService.getAll();
		IModelAndView view = new IModelAndView("jsonView",list);	
		return view;
	}
	
	@RequestMapping("/getflexigridview.htm")
	public IModelAndView getSettleHouseholdFromFlexigrid(FlexigridForm flexigridForm) {
		Long l = System.currentTimeMillis();
		List<SettleHousehold> list = settleHouseholdService.getFromFlexigrid(flexigridForm);
		Long l2 = System.currentTimeMillis();
		System.out.println("运行了："+(l2-l)+"毫秒");
		IModelAndView view = new IModelAndView("jsonView",list);		
		view.addObject("total",flexigridForm.getTotal());
		view.addObject("page",flexigridForm.getPage());
		view.addObject("rows",IFlexigridJson.getRows(list));
		return view;
	}
}
